﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Http.Headers;
using Water.Model;
using WaterApp.Common;

namespace WaterApp.Business
{
    public partial class Ajax : System.Web.UI.Page
    {
        private string _paramValue = "", _paramType = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["paramvalue"] != null)
            {
                _paramValue = Server.UrlDecode(Request["paramvalue"].ToString());
            }
            if (Request["paramtype"] != null)
            {
                _paramType = Request["paramtype"].ToString();
            }

            Response.Write(buildHtml(_paramValue, _paramType));
        }

        public StringBuilder buildHtml(string prparamValue, string prparamType)
        {
            StringBuilder returnValue = null;
            switch (prparamType)
            {
                #region BuilderChartF02001
                case "BuilderChart":
                    string chartno = prparamValue;
                    string url = WebapiUrl.weburl() + "GetChartBuildMana/" + chartno + "/admin";
                    HttpClient httpClient = new HttpClient();
                    var response = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                    ChartBuildMana mr = JsonConvert.DeserializeObject<ChartBuildMana>(response);
                    returnValue = new StringBuilder();
                    //ChartBuildMana chartbm = new ChartBuildMana().getSecChartBuild(chartno, "admin");
                    if (mr.chartno != null)
                    {
                        returnValue.Append(JsonHelper.ObjectToJson(mr));
                    }
                    else
                    {
                        returnValue.Append("NONE");
                    }
                    break;
                #endregion
                default:
                    break;
            }
            return returnValue;
        }
    }
}